package com.schedule.controller.user;

import com.schedule.daoVo.ScheduleVo;
import com.schedule.dto.ScheduleDto;
import com.schedule.dto.SchedulePageDto;
import com.schedule.mapper.ScheduleMapper;
import com.schedule.result.PageResult;
import com.schedule.result.Result;
import com.schedule.server.ScheduleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/schedule")
@Tag(name = "用户课程管理")
public class ScheduleTableController {

    @Autowired
    private ScheduleService scheduleService;
    /***
     *
     * 获取该用户的所有日志计划
     * ***/
    @GetMapping("/selectData")
    @Operation(summary = "获取该用户的课程数据")
    public Result <List<ScheduleVo>> SelectTable(){
        List<ScheduleVo> scheduleVo=new ArrayList<>();
        scheduleVo.addAll(scheduleService.SelectData());
        return Result.success(scheduleVo);
    }


    @GetMapping("/page")
    @Operation(summary = "分页查询")
    public Result<PageResult> PageSchedule(SchedulePageDto schedulePageDto){
       PageResult pageResult=scheduleService.PageQuery(schedulePageDto) ;
        return Result.success(pageResult);
    }


    /**
     * @param scheduleDto
     * @return 添加计划数据
     * ***/
    @PostMapping("/createSchedule")
    @Operation(summary = "添加的数据")
    public Result CreateSchedule(@RequestBody ScheduleDto scheduleDto){
       scheduleService.CISchedule(scheduleDto);
        return Result.success("插入成功");
    }

    /*****
     * @param ids
     * @return 批量删除数据
     * ***/
    @DeleteMapping("/deleteSTable")
    @Operation(summary = "批量删除")
    public Result DLtable(@RequestBody List<Long> ids){
        if (ids == null || ids.isEmpty()) {
            return Result.error("请传入要删除的日程ID列表");
        }
        int count = scheduleService.DeleteSchedulesByIds(ids);
        return Result.success(count);
    }

}
